home *** CD-ROM | disk | FTP | other *** search
- /*******************************
- File: OQD_Test.c
- Function: Handle OQD_Test window
- *******************************/
- #include "OQD_Test.h"
- #include "OQDKolorize.h"
- #include "String.h"
-
- #define TRUE 1
- #define FALSE 0
- #define NIL 0
-
- static void Do_Button(ControlHandle theControl);
- static void ClearRadioGroup(void);
- static void Do_A_Checkbox(ControlHandle theControl);
-
-
- /* *********************************** */
- extern int checkmark;
- extern int colorSelection[4];
-
- /* Control IDs */
- #define ButtonID 28
- #define CheckboxID 30
- #define Radio1ID 29
- #define Radio2ID 31
-
- WindowPtr MyWindow;
- static ControlHandle theButton;
- static ControlHandle theCheckbox;
- static ControlHandle theRadio[3];
-
- void Init_OQD_Test()
- /* initialize OQD_Test window */
- {
- MyWindow = NIL;
- }
-
- void Close_OQD_Test(whichWindow)
- /* dispose of OQD_Test window */
- WindowPtr whichWindow;
- {
-
- if ((MyWindow != NIL) &&
- ((MyWindow == whichWindow) || (whichWindow == (WindowPtr)-1))) {
- DisposeWindow(MyWindow);
- MyWindow = NIL;
- }
- }
-
- void DrawTheRect(theRect, theColor)
- Rect *theRect;
- int theColor;
- /* draws & frames rectangle with color */
- {
- FrameRect(theRect);
- InsetRect(theRect, 1, 1);
- ForeColor(theColor);
- PaintRect(theRect);
- ForeColor(blackColor);
- }
- void UpDate_OQD_Test(whichWindow)
- WindowPtr whichWindow;
- /* update window */
- {
- WindowPtr SavePort;
- Str255 sTemp;
- Rect tempRect;
- int pallete[4];
-
- if ((MyWindow != NIL) && (MyWindow == whichWindow)) {
- GetPort(&SavePort);
- SetPort(MyWindow);
-
- /* Draw solid color rectangles */
- SetRect(&tempRect, 20,40,80,100);
- DrawTheRect(&tempRect, blackColor);
- SetRect(&tempRect, 100,40,160,100);
- DrawTheRect(&tempRect, whiteColor);
- SetRect(&tempRect, 260,40,320,100);
- DrawTheRect(&tempRect, greenColor);
- SetRect(&tempRect, 180,40,240,100);
- DrawTheRect(&tempRect, redColor);
- SetRect(&tempRect, 260,140,320,200);
- DrawTheRect(&tempRect, yellowColor);
- SetRect(&tempRect, 180,140,240,200);
- DrawTheRect(&tempRect, magentaColor);
- SetRect(&tempRect, 100,140,160,200);
- DrawTheRect(&tempRect, cyanColor);
- SetRect(&tempRect, 20,140,80,200);
- DrawTheRect(&tempRect, blueColor);
-
- /* Draw Mixed rectangle according to percentages */
- SetRect(&tempRect, 360,100,420,160);
- FrameRect(&tempRect);
- InsetRect(&tempRect, 1, 1);
- switch (checkmark) {
- case 1: /* 75-25-0-0% of colorSelection */
- pallete[0] = pallete[1] = pallete[2] = colorSelection[0];
- pallete[3] = colorSelection[1];
- break;
- case 2: /* 50-50-0-0% of colorSelection */
- pallete[0] = pallete[1] = colorSelection[0];
- pallete[2] = pallete[3] = colorSelection[1];
- break;
- case 3: /* 50-25-25-0% of colorSelection */
- pallete[0] = pallete[1] = colorSelection[0];
- pallete[2] = colorSelection[1];
- pallete[3] = colorSelection[2];
- break;
- case 4: /* 25-25-25-25% of colorSelection */
- pallete[0] = colorSelection[0];
- pallete[1] = colorSelection[1];
- pallete[2] = colorSelection[2];
- pallete[3] = colorSelection[3];
- break;
- }
- PaintMixedRect(&tempRect, pallete);
-
- TextFont(systemFont);
- /* Draw titles */
- SetRect(&tempRect, 20,20,80,40);
- strcpy((char *)&sTemp,"\pBlack");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 100,20,160,40);
- strcpy((char *)&sTemp,"\pWhite");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 180,20,240,40);
- strcpy((char *)&sTemp,"\pRed");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 20,120,80,140);
- strcpy((char *)&sTemp,"\pBlue");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 260,20,320,40);
- strcpy((char *)&sTemp,"\pGreen");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 100,120,160,140);
- strcpy((char *)&sTemp,"\pCyan");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 180,120,240,140);
- strcpy((char *)&sTemp,"\pMagenta");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 260,120,320,140);
- strcpy((char *)&sTemp,"\pYellow");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
-
- SetRect(&tempRect, 360,80,420,100);
- strcpy((char *)&sTemp,"\pMixed");
- TextBox(&sTemp[1], sTemp[0], &tempRect, teJustLeft);
- KolorizeMix(&tempRect, pallete);
- TextFont(applFont);
-
- DrawControls(MyWindow);
-
- KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
-
- if (GetCtlValue(theRadio[0]))
- KolorizeCDEF(theRadio[0], radioButProc, cyanColor, redColor);
- else
- KolorizeCDEF(theRadio[0], radioButProc, magentaColor, redColor);
-
- if (GetCtlValue(theRadio[1]))
- KolorizeCDEF(theRadio[1], radioButProc, cyanColor, redColor);
- else
- KolorizeCDEF(theRadio[1], radioButProc, magentaColor, redColor);
-
- KolorizeCDEF(theCheckbox, checkBoxProc, greenColor, redColor);
- SetPort(SavePort);
- }
- }
-
- void Open_OQD_Test(void)
- /* open OQD_Test window */
- {
- Rect tempRect;
-
- if (MyWindow == NIL) {
- MyWindow = GetNewWindow(1,NIL, (WindowPtr)-1);
- tempRect = MyWindow->portRect;
- tempRect.top = ((screenBits.bounds.bottom - screenBits.bounds.top)
- - (tempRect.bottom - tempRect.top)) / 2 + 20;
- tempRect.left = ((screenBits.bounds.right - screenBits.bounds.left)
- - (tempRect.right - tempRect.left)) / 2;
-
- MoveWindow(MyWindow, tempRect.left, tempRect.top, TRUE);
- SetPort(MyWindow);
-
- /* Make buttons */
- theButton = GetNewControl(ButtonID,MyWindow);
- theCheckbox = GetNewControl(CheckboxID,MyWindow);
- theRadio[0] = GetNewControl (Radio1ID, MyWindow);
- theRadio[1] = GetNewControl (Radio2ID, MyWindow);
-
- ShowWindow(MyWindow);
- SelectWindow(MyWindow);
- UpDate_OQD_Test(MyWindow);
- }
- else
- SelectWindow(MyWindow);
- }
-
- static void DoCheckbox(theControl)
- ControlHandle theControl;
- /* handle setting and kolorizing push and radio buttons */
- {
- short theValue;
-
- if (theControl == theCheckbox) { /* pushbutton */
- theValue = GetCtlValue(theControl);
- theValue = (theValue + 1) & 1;
- SetCtlValue(theControl, theValue);
- }
- else { /* radio buttons */
- SetCtlValue(theRadio[0],0);
- SetCtlValue(theRadio[1],0);
- SetCtlValue(theControl, 1);
- }
- }
-
- void Do_OQD_Test(myEvent)
- /* handle mouse downs in controls */
- EventRecord *myEvent;
- {
- short code;
- WindowPtr whichWindow;
- Point myPt;
- ControlHandle theControl;
-
- if (MyWindow != NIL) { /* make sure our window */
- code = FindWindow(myEvent->where, &whichWindow);
-
- /* see if mouse down */
- if ((myEvent->what == mouseDown) && (MyWindow == whichWindow)) {
- myPt = myEvent->where;
- GlobalToLocal(&myPt);
- }
-
- /* see if control */
- if ((MyWindow == whichWindow) && (code == inContent)) {
- code = FindControl(myPt, whichWindow, &theControl);
- if (code != 0)
- code = TrackControl(theControl,myPt, NIL);
- if (code == inButton) /* only 1 button - Kolorize */
- KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
- if (code == inCheckBox) /* handle pushbutton and radios */
- DoCheckbox(theControl);
- KolorizeCDEF(theButton, pushButProc, cyanColor, cyanColor);
-
- /* Kolorize radios and checkbox */
- if (GetCtlValue(theRadio[0]))
- KolorizeCDEF(theRadio[0], radioButProc, cyanColor, redColor);
- else
- KolorizeCDEF(theRadio[0], radioButProc, magentaColor, redColor);
-
- if (GetCtlValue(theRadio[1]))
- KolorizeCDEF(theRadio[1], radioButProc, cyanColor, redColor);
- else
- KolorizeCDEF(theRadio[1], radioButProc, magentaColor, redColor);
-
- KolorizeCDEF(theCheckbox, checkBoxProc, greenColor, redColor);
- }
- }
- }
-
-
-